const express=require('express');
const bodyParser=require('body-parser');
const cookieParser=require('cookie-parser');

let app=express();
app.use(express.static('.'));
app.use(cookieParser());
app.get('/',function(request,response){
    console.log('GET');
    response.send(`Welcome ${JSON.stringify(request.cookies)}`);
});
app.get('/login',function(request,response){
    response.send(
        `<form action="/submit" method="POST">
            PWD: <input type="password" name="password"/><br/>
            <input type="submit" value="SUBMIT"/>
        </form>`
    );
});
let parser=bodyParser.urlencoded({extended:false});
app.post('/submit',parser,function(request,response){
    let reply={password:request.body.password};
    response.end(JSON.stringify(reply));
});
let server=app.listen(8080,function(){
    let info=server.address();
    let host=info.address;
    let port=info.port;
    console.log(`Server running at http://${host}:${port}`);
});
